﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DPS.Prototype.PolicyBase;
using DPS.Prototype.Extension;

namespace DPS.Prototype.Model
{
    [Inspect]
    public class SubmitResult
    {
        public WorkOrder WorkOrder { get; set; }
        public ProdLine ProdLine { get; set; }

        [Inspect(OrderNo=2)]
        internal string WorkOrderNo { get { return this.WorkOrder.OrderNo; } }
        [Inspect(OrderNo=3)]
        public DateTime StartTime { get; set; }
        [Inspect(OrderNo =4)]
        public DateTime FinishTime { get; set; }
        [Inspect(OrderNo = 5)]
        public float ProduceQty { get; set; }
        [Inspect(OrderNo = 4)]
        internal string ProdLineNo { get { return this.ProdLine.LineNo; } }

        
        public override string ToString()
        {
            string formatStr = "WorkOrder: {0},ProdLine: {1}, StartTime: {2},FinishTime: {3},ProduceQty: {4}";
            return string.Format(formatStr, this.WorkOrder.OrderNo, this.ProdLine.LineNo, this.StartTime, this.FinishTime, this.ProduceQty);
        }

        public void Submit()
        {
            WorkOrder order = WorkOrderPool.WorkOrderList.Find(wo => wo.Equals(this.WorkOrder));
            order.BuildDate = this.StartTime;
            order.WorkOrderStatus = WorkOrderStatus.Assigned;
            order.AssignedProducLine = this.ProdLine;
            order.OpenOrderQty = order.OpenOrderQty - this.ProduceQty;
        }

        public void Abandon()
        {
            WorkOrder order = WorkOrderPool.WorkOrderList.Find(wo => wo.Equals(this.WorkOrder));
            
        }
    }
}
